package com.shrbank.akka

import akka.actor.{ActorSystem, Props}
import com.typesafe.config.ConfigFactory

/**
 * Hello world!
 *
 */
object AkkaClusterSystem {
  def main(args: Array[String]): Unit = {
    if (args.isEmpty)
      startup(Seq("2551", "2552", "0"))
    else
      startup(args)
    println( "Hello World!" )
  }
  def startup(ports: Seq[String]): Unit = {
    ports foreach { port =>
      // Override the configuration of the port
      val config = ConfigFactory.parseString("akka.remote.netty.tcp.port=" + port).
        withFallback(ConfigFactory.load("cluster.conf"))

      // Create an Akka system
      val system = ActorSystem.create("ClusterSystem", config)
      // Create an actor that handles cluster domain events
      system.actorOf(Props[AkkaCluster], name = "clusterListener")
    }
  }
}
